package org.os.framework.crypto.engine;

import java.math.BigInteger;
import java.security.SecureRandom;

/**
 * @author
 */
public class RandomCalculator {
    private BigInteger n;
    private SecureRandom random;

    public RandomCalculator(BigInteger n, SecureRandom random) {
        this.n = n;
        this.random = random;
    }

    public BigInteger nextK() {
        BigInteger k;
        do {
            k = BigInteger.valueOf(random.nextInt(n.bitLength()));
        } while (k.compareTo(BigInteger.ZERO) == 0 || k.compareTo(n) >= 0);
        return k;
    }
}
